/*
Navicat PGSQL Data Transfer

Source Server         : test
Source Server Version : 90303
Source Host           : localhost:5432
Source Database       : testMZ
Source Schema         : public

Target Server Type    : PGSQL
Target Server Version : 90303
File Encoding         : 65001

Date: 2014-07-10 16:15:44
*/


-- ----------------------------
-- Sequence structure for "ierarchy_id_seq"
-- ----------------------------
DROP SEQUENCE "ierarchy_id_seq";
CREATE SEQUENCE "ierarchy_id_seq"
 INCREMENT 1
 MINVALUE 1
 MAXVALUE 9223372036854775807
 START 22
 CACHE 1;

-- ----------------------------
-- Sequence structure for "valves_id_seq"
-- ----------------------------
DROP SEQUENCE "valves_id_seq";
CREATE SEQUENCE "valves_id_seq"
 INCREMENT 1
 MINVALUE 1
 MAXVALUE 9223372036854775807
 START 18
 CACHE 1;

-- ----------------------------
-- Table structure for "ierarchy"
-- ----------------------------
DROP TABLE "ierarchy";
CREATE TABLE "ierarchy" (
"id" int4 DEFAULT nextval('ierarchy_id_seq'::regclass) NOT NULL,
"p_id" int4 NOT NULL,
"c_id" int4 NOT NULL,
"p_o" int4 NOT NULL,
"c_i" int4 NOT NULL
)
WITH (OIDS=FALSE)

;

-- ----------------------------
-- Records of ierarchy
-- ----------------------------
BEGIN;
INSERT INTO "ierarchy" VALUES ('1', '1', '3', '1', '1');
INSERT INTO "ierarchy" VALUES ('2', '2', '3', '1', '2');
INSERT INTO "ierarchy" VALUES ('3', '1', '4', '2', '1');
INSERT INTO "ierarchy" VALUES ('4', '2', '4', '2', '2');
INSERT INTO "ierarchy" VALUES ('5', '8', '5', '1', '1');
INSERT INTO "ierarchy" VALUES ('6', '8', '5', '2', '2');
INSERT INTO "ierarchy" VALUES ('9', '3', '7', '2', '1');
INSERT INTO "ierarchy" VALUES ('10', '4', '7', '2', '2');
INSERT INTO "ierarchy" VALUES ('11', '3', '6', '1', '1');
INSERT INTO "ierarchy" VALUES ('12', '4', '6', '1', '2');
COMMIT;

-- ----------------------------
-- Table structure for "valves"
-- ----------------------------
DROP TABLE "valves";
CREATE TABLE "valves" (
"id" int4 DEFAULT nextval('valves_id_seq'::regclass) NOT NULL,
"v_name" text NOT NULL,
"input" int4 NOT NULL,
"output" int4 NOT NULL,
"state" bool NOT NULL
)
WITH (OIDS=FALSE)

;

-- ----------------------------
-- Records of valves
-- ----------------------------
BEGIN;
INSERT INTO "valves" VALUES ('1', 'c1', '0', '3', 't');
INSERT INTO "valves" VALUES ('2', 'c2', '0', '3', 't');
INSERT INTO "valves" VALUES ('3', 'k1', '2', '2', 't');
INSERT INTO "valves" VALUES ('4', 'k2', '2', '2', 't');
INSERT INTO "valves" VALUES ('5', 'k3', '2', '2', 'f');
INSERT INTO "valves" VALUES ('6', 'c3', '3', '0', 't');
INSERT INTO "valves" VALUES ('7', 'c4', '3', '0', 't');
INSERT INTO "valves" VALUES ('8', 'c5', '0', '2', 'f');
COMMIT;

-- ----------------------------
-- Alter Sequences Owned By 
-- ----------------------------
ALTER SEQUENCE "ierarchy_id_seq" OWNED BY "ierarchy"."id";
ALTER SEQUENCE "valves_id_seq" OWNED BY "valves"."id";

-- ----------------------------
-- Uniques structure for table "ierarchy"
-- ----------------------------
ALTER TABLE "ierarchy" ADD UNIQUE ("c_id", "c_i");

-- ----------------------------
-- Primary Key structure for table "ierarchy"
-- ----------------------------
ALTER TABLE "ierarchy" ADD PRIMARY KEY ("id");

-- ----------------------------
-- Uniques structure for table "valves"
-- ----------------------------
ALTER TABLE "valves" ADD UNIQUE ("v_name");

-- ----------------------------
-- Primary Key structure for table "valves"
-- ----------------------------
ALTER TABLE "valves" ADD PRIMARY KEY ("id");

-- ----------------------------
-- Foreign Key structure for table "ierarchy"
-- ----------------------------
ALTER TABLE "ierarchy" ADD FOREIGN KEY ("c_id") REFERENCES "valves" ("id") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "ierarchy" ADD FOREIGN KEY ("p_id") REFERENCES "valves" ("id") ON DELETE CASCADE ON UPDATE CASCADE;
